//
//  FileImageBaseView.m
//  SBooks
//
//  Created by shansander on 2016/11/16.
//  Copyright © 2016年 shansander. All rights reserved.
//

#import "FileImageBaseView.h"
CGFloat const define_max_image_size_widht = 968.0f;
CGFloat const define_max_image_size_height = 1024.0f;
CGFloat const define_title_origin_x = 40.0f;
CGFloat const define_title_origin_y = 380.0f;
CGFloat const define_title_size_width = 570.0f;
CGFloat const define_title_size_height = 334.0f;

@implementation FileImageBaseView

- (void)awakeFromNib
{
    [super awakeFromNib];
    NSLog(@"%@",NSStringFromCGRect(self.bounds));
    per_size_width = self.bounds.size.width/define_max_image_size_widht;
    per_size_height = self.bounds.size.height/define_max_image_size_height;
    [self configView];
}

- (instancetype)init
{
    self = [super init];
    if (self) {
        
    }
    return self;
}

- (void)configView
{
    self.backgroundColor = [UIColor clearColor];
    UIImage * image = [UIImage imageNamed:@"fileTypeImage"];
    image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
    
    UIImageView * theDefineView = [[UIImageView alloc] initWithFrame:self.bounds];
    [theDefineView setImage:image];
    [self addSubview:theDefineView];
    [theDefineView setTintColor:[UIColor grayColor]];
    
    theTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(per_size_width * define_title_origin_x, per_size_height * define_title_origin_y, per_size_width * define_title_size_width, per_size_height * define_title_size_height)];
    theTitleLabel.textColor = [UIColor blackColor];
    theTitleLabel.textAlignment = NSTextAlignmentCenter;
    theTitleLabel.font = [UIFont systemFontOfSize:13];
    theTitleLabel.textColor = [UIColor grayColor];
    [self addSubview:theTitleLabel];
    
    
}

- (void)loadFileName:(NSString * )filename
{
    NSArray * fileNameList = [filename componentsSeparatedByString:@"."];
    
    NSString * fileType = fileNameList.lastObject;
    if (!fileType) {
        // 文件类型未知
        fileType = @"***";
    }
    
    theTitleLabel.text = fileType;
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
